﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Framework.ExtensionsMods.RemoteRequest
{
	/// <summary>
	/// Http远程请求参考类
	/// </summary>
	public class HttpItem
	{
		TimeSpan _Timeout = new TimeSpan(0, 3, 0);
		/// <summary>
		/// 默认请求超时时间
		/// </summary>
		public TimeSpan Timeout
		{
			get { return _Timeout; }
			set { _Timeout = value; }
		}
		
		/// <summary>
		/// 设置Host的标头信息
		/// </summary>
		public string Host { get; set; }

		Boolean _KeepAlive = false;
		/// <summary>
		///  获取或设置一个值，该值指示是否与 Internet 资源建立持久性连接默认为false。
		/// </summary>
		public Boolean KeepAlive
		{
			get { return _KeepAlive; }
			set { _KeepAlive = value; }
		}

		string _Accept = "text/html, application/xhtml+xml, */*";
		/// <summary>
		/// 请求标头值 默认为text/html, application/xhtml+xml, */*
		/// </summary>
		public string Accept
		{
			get { return _Accept; }
			set { _Accept = value; }
		}
		string _ContentType = "text/html";
		/// <summary>
		/// 请求返回类型默认 text/html
		/// </summary>
		public string ContentType
		{
			get { return _ContentType; }
			set { _ContentType = value; }
		}
		string _UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)";
		/// <summary>
		/// 客户端访问信息默认Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)
		/// </summary>
		public string UserAgent
		{
			get { return _UserAgent; }
			set { _UserAgent = value; }
		}
		/// <summary>
		/// 返回数据编码默认为NUll,可以自动识别,一般为utf-8,gbk,gb2312
		/// </summary>
		public Encoding Encoding { get; set; }

		string _Postdata = "";
		/// <summary>
		/// Post请求时要发送的字符串Post数据
		/// </summary>
		public string Postdata
		{
			get { return _Postdata; }
			set { _Postdata = value; }
		}
		/// <summary>
		/// Post请求时要发送的Byte类型的Post数据
		/// </summary>
		public byte[] PostdataByte { get; set; }
		/// <summary>
		/// Cookie对象集合
		/// </summary>
		public CookieCollection CookieCollection { get; set; }
		/// <summary>
		/// 请求时的Cookie
		/// </summary>
		public string Cookie { get; set; }
		/// <summary>
		/// 来源地址，上次访问地址
		/// </summary>
		public string Referer { get; set; }

		private Boolean isToLower = false;
		/// <summary>
		/// 是否设置为全文小写，默认为不转化
		/// </summary>
		public Boolean IsToLower
		{
			get { return isToLower; }
			set { isToLower = value; }
		}

		private int connectionlimit = 1024;
		/// <summary>
		/// 最大连接数
		/// </summary>
		public int Connectionlimit
		{
			get { return connectionlimit; }
			set { connectionlimit = value; }
		}
		/// <summary>
		/// 代理Proxy 服务器用户名
		/// </summary>
		public string ProxyUserName { get; set; }
		/// <summary>
		/// 代理 服务器密码
		/// </summary>
		public string ProxyPwd { get; set; }
		/// <summary>
		/// 代理 服务IP
		/// </summary>
		public string ProxyIp { get; set; }

		private Dictionary<string, string> header = new Dictionary<string, string>();
		/// <summary>
		/// header对象
		/// </summary>
		public Dictionary<string, string> Header
		{
			get { return header; }
			set { header = value; }
		}
		/// <summary>
		/// 获取或设置用于请求的 HTTP 版本。返回结果:用于请求的 HTTP 版本。
		/// </summary>
		public string Protocol { get; set; }


		Encoding _PostEncoding = Encoding.Default;
		/// 设置或获取Post参数编码,默认的为Default编码
		/// </summary>
		public Encoding PostEncoding
		{
			get { return _PostEncoding; }
			set { _PostEncoding = value; }
		}
	}
}
